package com.tai.cobrapp.adapter;

import java.util.ArrayList;

import com.tai.cobrapp.R;
import com.tai.cobrapp.model.DetalleRelevamiento;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class NewSurveyListAdapter extends BaseAdapter {

	Context context = null;
	ArrayList<DetalleRelevamiento> data = null;
	LayoutInflater inflater = null;
	
	public NewSurveyListAdapter(Context context, ArrayList<DetalleRelevamiento> data){
		this.context = context;
		this.data = data;
		this.inflater = ((Activity)context).getLayoutInflater();
	}
	public void SetSurveyList(ArrayList<DetalleRelevamiento> data){
		this.data = data;
	}
	@Override
	public int getCount() {
		return this.data.size();
	}

	@Override
	public Object getItem(int position) {
		return this.data.get(position);
	}

	@Override
	public long getItemId(int arg0) {
		// Raramente se usa
		return 0;
	}

	@Override
	public View getView(int position, View view, ViewGroup arg2) {
		view = inflater.inflate(R.layout.detail_survey_list_adapter, null);
		
		TextView title = (TextView)view.findViewById(R.id.title_textView);
		title.setText(((DetalleRelevamiento)this.getItem(position)).getDispositivo().getName().toString());
		
		TextView turnoMan = (TextView)view.findViewById(R.id.turnoMan_textView);
		TextView turnoTar = (TextView)view.findViewById(R.id.turnoTar_textView);
		
		TextView subtitle = (TextView)view.findViewById(R.id.subtitle_textView);
		
		// No hace falta por ahora cambiar la imagen en el adapter
		//ImageView image = (ImageView)view.findViewById(R.id.iconListRelev);
		//image.setImageResource(R.drawable.ic_tv);
		
		
		if(((DetalleRelevamiento)this.getItem(position)).isVendido()){
			subtitle.setText(context.getString(R.string.amount) + ": $" + ((DetalleRelevamiento)this.getItem(position)).getMontoUnitario().toString());
			title.setTextColor(Color.GREEN);
			turnoMan.setTextColor(((DetalleRelevamiento)this.getItem(position)).isTurnoManiana() ? Color.GREEN : Color.RED);
			turnoTar.setTextColor(((DetalleRelevamiento)this.getItem(position)).isTurnoTarde() ? Color.GREEN : Color.RED);
		}else{
			subtitle.setVisibility(View.INVISIBLE);
			title.setTextColor(Color.RED);
			turnoMan.setVisibility(View.INVISIBLE);
			turnoTar.setVisibility(View.INVISIBLE);
		}
		
		return view;
	}

}
